
package vv.lines.view.swing;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JComponent;
import vv.lines.view.CellView;

/**
 *
 * @author vpotapenko
 */
public class SwingCellView extends SwingFieldItem implements CellView {

    public Color getHighlightOuterColor()   {
        JComponent parent = getOwner();
        return parent != null? parent.getBackground().brighter().brighter() : Color.GRAY;
    }

    private Color getBackground() {
        JComponent parent = getOwner();
        return parent != null? parent.getBackground() : Color.GRAY;
    }

    private Color getHighlightInnerColor() {
        JComponent parent = getOwner();
        return parent != null? parent.getBackground().brighter() : Color.GRAY;
    }

    private Color getShadowInnerColor() {
        JComponent parent = getOwner();
        return parent != null? parent.getBackground().darker() : Color.GRAY;
    }

    private Color getShadowOuterColor() {
        JComponent parent = getOwner();
        return parent != null? parent.getBackground().darker().darker() : Color.GRAY;
    }

    @Override
    protected void paintObject(Graphics g) {
        int h = getHeight();
        int w = getWidth();
        int x = getX();
        int y = getY();

        Color oldColor = g.getColor();

        g.setColor(getBackground());
        g.fillRect(x, y, w, h);

        g.translate(x, y);

        g.setColor(getHighlightOuterColor());
        g.drawLine(0, 0, 0, h-2);
        g.drawLine(1, 0, w-2, 0);

        g.setColor(getHighlightInnerColor());
        g.drawLine(1, 1, 1, h-3);
        g.drawLine(2, 1, w-3, 1);

        g.setColor(getShadowOuterColor());
        g.drawLine(0, h-1, w-1, h-1);
        g.drawLine(w-1, 0, w-1, h-2);

        g.setColor(getShadowInnerColor());
        g.drawLine(1, h-2, w-2, h-2);
        g.drawLine(w-2, 1, w-2, h-3);

        g.translate(-x, -y);
        g.setColor(oldColor);
    }
}
